//
//  SignRedBottomView.swift
//  TianTianBiTing
//
//  Created by Gox mac 2 on 2019/3/1.
//  Copyright © 2019 Gox_WallyDiao. All rights reserved.
//

import UIKit

class SignRedBottomView: UIView {

    var checkBlock:(() -> Void)?
    var moneyLabel:UILabel = UILabel.init()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.clear
        setUI()
        setData()
        setMoneyData()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setUI() {
        self.backgroundColor = RGB_Same(0, 0.8)
        let backImageView = UIImageView.init(frame: FRAME_CGFloat(0, 60.5, SCREEN_WIDTH / 2 - 100, 155))
        self.addSubview(backImageView)
        backImageView.isUserInteractionEnabled = true
        backImageView.image = IMAGE(name: "signRedHeadBack")
        
        
        
        self.moneyLabel.frame = FRAME_CGFloat(SCREEN_WIDTH / 2 - 100, 10, 200, 88.8)
        self.moneyLabel.font = Font_Medium(63)
        self.moneyLabel.textColor = WhiteBackColor
        self.moneyLabel.textAlignment = .center
        self.moneyLabel.backgroundColor = .clear
        backImageView.addSubview(self.moneyLabel)
        
        let leftLabel = UILabel.init(frame: FRAME_CGFloat(SCREEN_WIDTH / 2 - 125, 65.5, 25, 15))
        leftLabel.font = FONT(11)
        leftLabel.textColor = RGB_Same(255)
        leftLabel.textAlignment = .right
        leftLabel.text = "已领"
        backImageView.addSubview(leftLabel)
        
        let rightLabel = UILabel.init(frame: FRAME_CGFloat(SCREEN_WIDTH / 2 + 100, 65.5, 25, 15))
        rightLabel.font = FONT(11)
        rightLabel.textColor = RGB_Same(255)
        rightLabel.textAlignment = .left
        rightLabel.text = "听币"
        backImageView.addSubview(rightLabel)
        
        let checkBtn = UIButton.init(type: .custom)
        checkBtn.setTitle("查看", for: .normal)
        checkBtn.setTitleColor(.white, for: .normal)
        backImageView.addSubview(checkBtn)
        checkBtn.titleLabel?.font = UIFont.boldSystemFont(ofSize: 13)
        checkBtn.frame = FRAME_CGFloat(SCREEN_WIDTH / 2 - 15, 93.5, 30, 18.5)
        checkBtn.addTarget(self, action: #selector(checkAction), for: .touchUpInside)
        backImageView.addSubview(checkBtn)
        
        let bottomLabel = UILabel.init(frame: FRAME_CGFloat(0, 135, SCREEN_WIDTH, 15))
        bottomLabel.font = FONT(11)
        bottomLabel.textColor = RGB_Same(255)
        bottomLabel.textAlignment = .center
        bottomLabel.text = "每日签到将送您0.1听币;连续签到7天，第七天可获得1听币超级奖励"
        backImageView.addSubview(bottomLabel)
        
    }
    
    func setData() {
        
    }
    
    func setMoneyData() {
        MineRequestModel.loadUserInfo(parameters: ["userId":String.getUserId()]) { (success, message, model) in
            if success && model != nil {
                self.moneyLabel.text = String.money(model?.rewardBalance ?? 0.0)
                //                self.moneyLabel.text = "99.99"
            }
        }
        
    }
    
    @objc func checkAction() {
        checkBlock?()
        
    }

}
